
ENT.Base = "base_entity"
ENT.Type = "brush"

/*---------------------------------------------------------
   Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()	
end

/*---------------------------------------------------------
   Name: StartTouch
---------------------------------------------------------*/
function ENT:StartTouch( entity )
	if (string.lower(entity:GetClass()) == "player") then
		zday.CurrentSearchbrush = self
	end
end

/*---------------------------------------------------------
   Name: EndTouch
---------------------------------------------------------*/
function ENT:EndTouch( entity )
	if (string.lower(zday.CurrentSearchbrush == self)) then
		zday.CurrentSearchbrush = nil
	end
end

/*---------------------------------------------------------
   Name: Touch
---------------------------------------------------------*/
function ENT:Touch( entity ) 
end

/*---------------------------------------------------------
   Name: PassesTriggerFilters
   Desc: Return true if this object should trigger us
---------------------------------------------------------*/
function ENT:PassesTriggerFilters( entity )
	if( entity:GetClass() == "player" ) then
		return true
	end
	return false
end

/*---------------------------------------------------------
   Name: KeyValue
   Desc: Called when a keyvalue is added to us
---------------------------------------------------------*/
function ENT:KeyValue( key, value )
	if (string.lower(key) == "name") then
		// Add it to the list of searchbrushes in this map
		local path = "zday/maps/" .. game.GetMap() .. "/search_brushes.txt"
		
		// Load if it already exists
		if (file.Exists(path)) then
			local tab = util.KeyValuesToTable(file.Read(path))
		end
		
		// Update it
		local tab = tab or {}
		
		// If it dosn't exist, add it
		if (!tab[value]) then
			tab[value] = {}
			tab[value]["classname"] = "percent_chance_to_find"
			file.Write(path, util.TableToKeyValues(tab))
		end
	end
end

/*---------------------------------------------------------
   Name: Think
   Desc: Entity's think function. 
---------------------------------------------------------*/
function ENT:Think()
end

/*---------------------------------------------------------
   Name: OnRemove
   Desc: Called just before entity is deleted
---------------------------------------------------------*/
function ENT:OnRemove()
end
